package smecta.client.print.controller;

import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RestController;
import smecta.client.print.util.AlertUtil;

import java.util.concurrent.ConcurrentHashMap;

@RestController
public class CounterweightController {

    @FXML
    private TextField weight;
    @FXML
    private Button confirmCloseButton;
    @FXML
    private Button confirmButton;
    ConcurrentHashMap<String, Object> cacheMap = ScpDataAcqController.cacheMap;

    @FXML
    private void handleConfirm() {
        String text = weight.getText();
        if (StringUtils.isBlank(text) || Integer.parseInt(text) <= 0){
            AlertUtil.infoFinishAutoClose("净重设置错误，不能为0", 2000L);
            return;
        }
        cacheMap.put("counterweight",text);
        TextArea textArea = (TextArea) cacheMap.get("isUse");
        textArea.setText("配重");
        Stage stage = (Stage) confirmButton.getScene().getWindow();
        stage.close();
    }

    @FXML
    private void handleCancel() {
        // 关闭窗口
        Stage stage = (Stage) confirmCloseButton.getScene().getWindow();
        stage.close();
    }

}
